package com.lagou.edu.controller;

import com.lagou.edu.pojo.Resume;
import com.lagou.edu.service.ResumeService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * 简历控制器
 */
@Controller
@RequestMapping("/resume")
public class ResumeController {

    @Autowired
    private ResumeService resumeService;

    /**
     * 列表页面
     * @return
     */
    @RequestMapping("/queryList")
    public ModelAndView queryList() {
        // 查询所有简历lieb
        List<Resume> resumes = resumeService.queryList();
        for (Resume resume : resumes) {
            System.out.println(resume);
        }
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/list");
        modelAndView.addObject("resumes", resumes);
        return modelAndView;
    }

    /**
     * 跳转到新增或者修改页面
     * @return
     */
    @RequestMapping("/toAdd")
    public ModelAndView toAdd(Resume resume) {
        ModelAndView modelAndView = new ModelAndView();
        if(resume == null) {
            resume = new Resume();
        }
        modelAndView.setViewName("/add");
        modelAndView.addObject("resume", resume);
        return modelAndView;
    }

    /**
     * 新增或更新操作
     * @param Resume
     * @return
     */
    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(Resume Resume) {
        resumeService.saveOrUpdate(Resume);
        return "forward:../resume/queryList/";
    }

    /**
     * 删除操作
     * @param id
     * @return
     */
    @RequestMapping("/delete")
    public String delete(Long id) {
        resumeService.deleteById(id);
        return "forward:../resume/queryList/";
    }
}
